package cn.com.panda.utils;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.Set;

/**
 * created by liujunlin on 2022/3/14 15:56
 */
public class SharedPreferencesUtil {

    private Context context;
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;

    public SharedPreferencesUtil(Context context){
        this.context = context;
        initData();
    }

    private void initData() {
        sharedPreferences = context.getSharedPreferences("cncompanda",Context.MODE_PRIVATE);
        editor = sharedPreferences.edit();

    }

    public void saveString(String key, String str){
        editor.putString(key,str).apply();
    }

    public String getString(String key){
        return sharedPreferences.getString(key,"");
    }

    public void saveInt(String key, int str){
        editor.putInt(key,str).apply();
    }

    public int getInt(String key){
        return sharedPreferences.getInt(key,Integer.MIN_VALUE);
    }

    public void saveLong(String key, Long str){
        editor.putLong(key,str).apply();
    }

    public Long getLong(String key){
        return sharedPreferences.getLong(key,Long.MIN_VALUE);
    }

    public void saveFloat(String key, Float str){
        editor.putFloat(key,str).apply();
    }

    public Float getFloat(String key){
        return sharedPreferences.getFloat(key,Float.MIN_VALUE);
    }

    public void saveBoolean(String key, Boolean str){
        editor.putBoolean(key,str).apply();
    }

    public Boolean getBoolean(String key){
        return sharedPreferences.getBoolean(key,false);
    }

    public void saveSet(String key, Set<String> set){
        editor.putStringSet(key,set).apply();
    }

    public Set<String> getSet(String key){
        return sharedPreferences.getStringSet(key,null);
    }
}
